package com.chinaztt.fda.parameter;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


public class ParameterSetting {
	private static final String TAG = new Throwable().getStackTrace()[0].getClassName();
	
	private static ParameterSetting mInstance = null;
	private SharedPreferences sp = null;

	private ParameterSetting(Context context) {
		sp = context.getSharedPreferences("parameter", Context.MODE_PRIVATE);
		initApplicationParameter();
	}
	
	public static ParameterSetting getInstance() {
		return mInstance;
	}
	
	public static void init(Context context) {
		if (mInstance == null) {
			mInstance = new ParameterSetting(context);			
		}
	}

	private boolean initApplicationParameter() {
		if (ParFlag.YES.equals(sp.getString(ParFlag.FIRST_RUN, ParFlag.YES))) {
			Editor edit = sp.edit();
			edit.putString(ParFlag.FIRST_RUN, ParFlag.NO);
			edit.putString(ParFlag.CUR_APN, "cmnet");
			edit.putString(ParFlag.HOST_IP, "119.4.225.34");
			edit.putString(ParFlag.HOST_PORT, "8888");
			edit.commit();
		}
		
//		Editor edit = sp.edit();
////		edit.putString(ParFlag.MERCHANT_ID, "302640154111003");
//		edit.putString(ParFlag.MERCHANT_ID, "10110010000015");
//		edit.commit();
		
		return true;
	}
	
	public boolean setParameter(String key, String value) {
		Editor edit = sp.edit();
		edit.putString(key, value);
		return edit.commit();
	}

	public String getParameter(String key, String defaultValue) {
		return sp.getString(key, defaultValue);
	}
}
